package main

import (
	"context"
	"git.900sui.cn/kc/base/utils"
	"git.900sui.cn/kc/kcgin"
	"git.900sui.cn/kc/kcgin/logs"
	"git.900sui.cn/kc/rpcinterface/client/market"
	"git.900sui.cn/kc/rpcinterface/client/order"
	"github.com/robfig/cron"
)

func main() {
	logs.Info("Environment Variable:MSF_ENV:", kcgin.KcConfig.RunMode)
	c := cron.New()
	//每15分钟执行一次
	_ = c.AddFunc("@every 15m", updateOvertimeFrozen)
	//每15分钟执行一次
	_ = c.AddFunc("@every 15m", updateOvertimeConsume)
	c.Start()
	select {}
}

//定期更新过期冻结面值-订单服务
func updateOvertimeFrozen() {
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("crontab.log.updateOvertimeFrozen"))
	rpcOrder := new(order.Share).Init()
	defer rpcOrder.Close()
	var rpcOrderRes bool
	if err := rpcOrder.UpdateOvertimeFrozen(context.Background(), "", &rpcOrderRes); err != nil {
		utils.Logerr.Printf("定期更新过期冻结面值-订单服务 失败，错误：%s\n", err.Error())
	}
	//utils.Logerr.Printf("定期更新过期冻结面值-订单服务 完成")
}

//定时将未支付消费更新为超时-营销服务
func updateOvertimeConsume() {
	new(utils.KcLog).GetInstance(kcgin.AppConfig.String("crontab.log.updateOvertimeConsume"))
	rpcMarket := new(market.Share).Init()
	defer rpcMarket.Close()
	var rpcMarketRes bool
	if err := rpcMarket.UpdateOvertimeConsume(context.Background(), "", &rpcMarketRes); err != nil {
		utils.Logerr.Printf("定时将未支付消费更新为超时-营销服务 失败，错误：%s\n", err.Error())
	}
	//utils.Logerr.Printf("定时将未支付消费更新为超时-营销服务 完成")
}
